package com.ssy.lingxi.common.constant.order;


import com.ssy.lingxi.common.language.LanguageHolder;

import java.util.Arrays;

/**
 * 下单模式枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-16
 */
public enum OrderModeEnum {

    /**
     * 进货单下单 - 1
     */
    BUYER(1, "进货单下单", OrderTypeEnum.SPOT_PURCHASING),

    /**
     * 手工下单 - 2
     */
    MANUAL(2, "手工下单", OrderTypeEnum.SPOT_PURCHASING),

    /**
     * 询价报价下单 - 3
     */
    QUOTATION(3, "询价报价下单", OrderTypeEnum.INQUIRY_TO_PURCHASE),

    /**
     * 需求报价下单 - 4
     */
    DEMAND(4, "需求报价下单", OrderTypeEnum.NEED_TO_PURCHASE),

    /**
     * 合并订单下单
     */
    MERGE(5, "合并订单下单", OrderTypeEnum.COLLECTIVE_PURCHASE),

    /**
     * 渠道直采进货单下单 - 6
     */
    CHANNEL_DIRECT_BUY(6, "渠道直采进货单下单", OrderTypeEnum.CHANNEL_STRAIGHT_MINING),

    /**
     * 渠道直采手工下单 - 7
     */
    CHANNEL_DIRECT_MANUAL(7, "渠道直采手工下单", OrderTypeEnum.CHANNEL_STRAIGHT_MINING),

    /**
     * 渠道现货进货单下单 - 8
     */
    CHANNEL_STOCK_BUY(8, "渠道现货进货单下单", OrderTypeEnum.CHANNEL_SPOT),

    /**
     * 渠道现货手工下单 - 9
     */
    CHANNEL_STOCK_MANUAL(9, "渠道现货手工下单", OrderTypeEnum.CHANNEL_SPOT),

    /**
     * 积分下单 - 10
     */
    RIGHT_POINT(10, "积分下单", OrderTypeEnum.CREDITS_EXCHANGE),

    /**
     * 渠道积分下单 - 11
     */
    CHANNEL_RIGHT_POINT(11, "渠道积分下单", OrderTypeEnum.CHANNEL_POINT_EXCHANGE),

    /**
     * SRM - 采购询价 - 12
     */
    PURCHASE_INQUIRY(12, "采购询价合同下单", OrderTypeEnum.QUERY_PRICE_CONTRACT),

    /**
     * SRM - 采购竞价 - 13
     */
    PURCHASE_PRICE_COMPETITION(13, "采购竞价合同下单", OrderTypeEnum.PRICE_COMPETITION_CONTRACT_PURCHASE),

    /**
     * SRM - 采购招标 - 14
     */
    PURCHASE_BIDDING(14, "采购招标合同下单", OrderTypeEnum.PURCHASE_CONTRACT_BIDDING),

    /**
     * 请购单下单 - 15
     */
    REQUISITION(15, "请购单下单", OrderTypeEnum.REQUISITION_TO_PURCHASE);

    OrderModeEnum(Integer code, String name, OrderTypeEnum orderTypeEnum) {
        this.code = code;
        this.orderTypeEnum = orderTypeEnum;
    }

    /**
     * 枚举值
     */
    private Integer code;

    /**
     * 对应的订单类型
     */
    private OrderTypeEnum orderTypeEnum;

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public OrderTypeEnum getOrderTypeEnum() {
        return orderTypeEnum;
    }

    /**
     * 根据枚举值获得名称
     * @param code 枚举值
     * @return 下单模式名称
     */
    public static String getNameByCode(Integer code) {
        return LanguageHolder.getName(OrderModeEnum.class, code);
    }

    /**
     * 根据下单模式枚举值，获得订单类型枚举值
     * @param code 下单模式枚举值
     * @return 订单类型枚举值
     */
    public static Integer getOrderTypeByCode(Integer code) {
        OrderModeEnum modeEnum = Arrays.stream(OrderModeEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(null);
        return modeEnum == null ? 0 : modeEnum.getOrderTypeEnum().getCode();
    }
}
